package server;

/**
 * @author HZF
 * @date 2020/6/27 10:01
 * @description http协议类工具，主要提供响应头信息，这里我们只提供
 * 200和404情况
 */
public class HttpProtocolUtil {

    /**
     * 为响应码200提供请求信息
     * @param contentLength
     * @return
     */
    public static String getHttpHeader200(long contentLength){
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html \n"+
                "Content-Length:" + contentLength + " \n" +
                "\r\n";
    }

    /**
     * 为响应码404提供请求信息
     * @return
     */
    public static String getHttpHeader404(){
        String str404 = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 NOT Found \n" +
                "Content-Type: text/html \n"+
                "Content-Length:" + str404.getBytes().length + " \n" +
                "\r\n" + str404;
    }
}
